package client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import com.cdyne.ws.weatherws.ArrayOfWeatherDescription;

import MashupModel.*;

import provider.WSProvider;

public class TravelPlannerWSClient 
{
	public static void main(String args[])
    throws IOException
    {
		URL url = new URL("http://localhost:9990/services?wsdl");
		QName qname = new QName("http://provider/", "WSProviderImplService");
		
		Service service = Service.create(url, qname);
		WSProvider provider = service.getPort(WSProvider.class);
		
		String input;
		String[] inputs;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		CityAirportInformationAndForecastModel model;
		
		do
		{
			System.out.println("Enter zipecode and/or city name" +
					" get weather infomation.  Type 'quit' for exit");
			input = br.readLine();
			inputs = input.split(" ");
			if(inputs.length == 1 && !input.equalsIgnoreCase("quit"))
			{
				model = provider.getAirportInfoAndForecastByZip(inputs[0]);
				for(Table t : model.getAirportsInfo())
				{
					System.out.println(t.getCityOrAirportName() + "\t"
							+ "*forecast goes to here*");
					//insert forecast call after "\t"
				}
			}
			else
			{
				input = "";
				for(int i = 1; i < inputs.length; i++)
				{
					input += inputs[i];
				}
				model = provider.getAirportInfoAndForecastByCityAndZip(inputs[0], input);
				for(Table t : model.getAirportsInfo())
				{
					System.out.println(t.getCityOrAirportName() + "\t"
							+ "*forecast goes to here*");
					//insert forecast call after "\t"
				}
			}
		}while(!input.equalsIgnoreCase("quit"));
    }
}
